Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle integer replies, implement a connect timeout and dynamic config in VCL #2

Merged
merged 6 commits into from
May 31, 2012

Conversation

noahwilliamsson
Copy link

Hi,

Please consider pulling the following patches (details available in the commit messages):
Noah Williamsson (6):
Handle REDIS_REPLY_INTEGER in vmod_call() and return it as a string
Initialize config (host, port) once per VCL instead of once every call
Implement a connect timeout for connecting to Redis, defaulting to 200ms
Allow the Redis server and timeout to be set in VCL via redis.init_redis()
Provide a commented out example of redis.init_redis() in examples/example.vcl
Fix typo in examples/example.vcl (redis.call -> redis.send)

Tested on 32- and 64-bit Linux aswell as Mac OS X with Varnish 3.0.2.

Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
Because the VCC specifies PRIV_CALL for vmod_send() and vmod_call(), the
vmod_priv argument is NULL for every call to these functions. This causes
the config struct to be re-allocated for every call.

This patch changes PRIV_CALL to PRIV_VCL, making the vmod_priv argument shared
between all calls to the module's functions within a given instance of a VCL.

The allocation of the config struct is also moved from redis_common() to
init_function().

Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
Use redisConnectWithTimeout() instead of redisConnect() to prevent
hanging for minutes when the host is down (i.e, not responding).

The default timeout is set to 200ms via REDIS_TIMEOUT_MS in vmod_redis.c.

Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
…dis()

By default libvmod-redis attempts to connect to the Redis server
at 127.0.0.1, port 6379 with a connect timeout of 200 ms.

This patch allows the Redis hostname, port and timeout to be configured
via VCL using redis.init_redis(hostname, port, timeout_ms);

VCL example:
  import redis;
  sub vcl_init {
    redis.init_redis("localhost", 6379, 200);
  }

Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
…mple.vcl

Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
@andreacampi
Copy link
Member

Awesome, thanks!

andreacampi pushed a commit that referenced this pull request May 31, 2012
Handle integer replies, implement a connect timeout and dynamic config in VCL
@andreacampi andreacampi merged commit 4397675 into zephirworks:master May 31, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants